<template>
  <div class="box">
    <div class="top">
      <div class="header">
        <div class="top-bar-item" 
            :class="list.Cid === CurrCategoryID?'selected':'' " 
            v-for='list in CategoryList'
            @click='checkmenu(list.Cid)'>
          {{list.Name}}
        </div>
      </div>
    </div>
    <indexlist :list='ActivityList' :adlist='Adlist'></indexlist>  
  </div>
</template>

<script>
  const imgutil = require('../../common/until.js')
  import indexlist from '../compontents/indexlist'
  import { Indicator } from 'mint-ui'
  export default {
    name: 'all',
    data () {
      return {
        ActivityList: [],
        CategoryList: [],
        CurrCategoryID: 1,
        Adlist: []
      }
    },
    created: function () {
      this.init()
      this.adlist();
    },
    methods: {
      init: function(){
        let vthis = this;
        Indicator.open({
          text: '加载中...',
          spinnerType: 'fading-circle'
        });
        vthis.$http('/pinhuoitem/GetHomeActivityList2',{cid:vthis.CurrCategoryID,debug:0},function(res){
          Indicator.close();
          if(res.Result){
            vthis.ActivityList = res.Data.ActivityList;
            vthis.CategoryList = res.Data.CategoryList;
            vthis.CurrCategoryID = res.Data.CurrCategoryID;
          }
        },'GET')
      },
      adlist: function(){
        let vthis = this
        vthis.$http('/ads/GetBannersFormTypeV2',{ AreaTypeID: 1, valueID: vthis.CurrCategoryID},function(res){
          if(res.Result){
            res.Data.ADList.map(item => {
              item.ImageUrl = imgutil.getUrl(item.ImageUrl, 400);
            })
            vthis.Adlist = res.Data.ADList;
          }
        },'GET') 
      },
      checkmenu: function(id){
        if(this.CurrCategoryID === id){
          return
        }
        this.CurrCategoryID = id;
        this.init()
        this.adlist()
      }
    },
    components:{
      indexlist
    }
  }
</script>
<style scoped>
  .box{
    width: 100%;
    padding-top: 42px;
  }
  .top{
    width: 100%;
    height: 42px;
    position: fixed;
    top: 0;
    width: 100%;
    max-width: 720px;
    z-index: 100;
    background-color: #fff;
  }
  .header{
    width: 100%;
    height: 42px;
    flex-direction:row;
    justify-content:space-around;
    display:flex;
    position:relative;
    overflow-x: scroll;
  }
  .top-bar-item {
    display:inline-block;
    text-align:center;
    height:40px;
    line-height:40px;
    font-size:16px;
    border-bottom:2px solid #fff;
  }
  .selected{
    border-bottom:2px solid #ee0b16;
    color: #ee0b16;
  }

</style>
